import sys
import os


def bin_to_mem(infile, outfile):
    binfile = open(infile, 'rb')
    binfile_content = binfile.read(os.path.getsize(infile))
    datafile = open(outfile, 'w')


    b0 = 0
    i = 0

    for b in  binfile_content:
        i = i + 1
        b0 = b
        array = []
        array.append(b0)
        datafile.write(bytearray(array).hex() + '\n')
    for j in range(8192-i):
        array = []
        array.append(0)
        datafile.write(bytearray(array).hex() + '\n')
    binfile.close()
    datafile.close()


if __name__ == '__main__':
    if len(sys.argv) == 3:
        bin_to_mem(sys.argv[1], sys.argv[2])
    else:
        print('Usage: %s binfile datafile' % sys.argv[0], sys.argv[1], sys.argv[2])
